<?php
/**
 * Things to alter navigation menu
 *
 * @package itx_themes
 * @subpackage calotropis
 */

/**
 * Function to display navigation menu in calotropis
 *
 * @uses wp_nav_menu()
 * @since 1.2
 *
 * @see wp_nav_menu() For possible values for the parameter.
 * @param string|array $args Optional. Override defaults.
 */
function calotropis_menu($args=''){
    extract(itx_get_option('menu'));
    $args=(wp_parse_args($args));
    if ( function_exists('wp_nav_menu') && $wp_menu){
        if ($home) {
            add_filter( 'wp_nav_menu_items', 'calotropis_'.$args['theme_location'].'_home');
        }
        $passed_args=array('container'=>false,'fallback_cb'=>'calotropis_menu_','depth'=>$depth);
        wp_nav_menu(wp_parse_args($passed_args,$args));
        return;
    } else calotropis_menu_($args);
}

function calotropis_primary_home($args){
    return '<li><a href="'.get_option('home').'">'.itx_get_option('menu','home').'</a></li>'.$args;
}

/**
 * Function to display navigation menu in Calotropis if user choose to use Calotropis Menu or for older than WordPress 3.0 users
 *
 * @since 1.2
 *
 */
function calotropis_menu_($args){
	$class=$cat_inc=$page_inc='';
    extract(itx_get_option('menu'));
    extract(wp_parse_args($args));

    if ($show){
        echo '<ul class="sf-menu'.$class.'">';
        if ($home) echo '<li><a href="'.get_option('home').'">'.$home.'</a></li>';

        if ($cat_inc){
          @sort($cat_inc);
          $cat_inc=@implode(',',$cat_inc);
          $opt="&include=$cat_inc";
          if ($cat_sortby) {$opt.="&orderby=".$cat_sortby;};
          if ($cat_order) {$opt.="&order=".$cat_order;};
          $cat_args="title_li=&depth=$depth$opt";
        } else {
          $cat_args='title_li=&number=9';
        }

        if ($page_inc){
          @sort($page_inc);
          $page_inc=@implode(',',$page_inc);
          $opt="&include=$page_inc";
          if ($cat_sortby) {$opt.="&orderby=".$cat_sortby;};
          if ($cat_order) {$opt.="&order=".$cat_order;};
          $page_args="title_li=&depth=$depth$opt";
        } else {
          $page_args='title_li=&number=9';
        }

        if ($show=='cat'){
            wp_list_categories($cat_args);
        } elseif ($show=='page'){
            wp_list_pages($page_args);
        } elseif ($show=='cp'){
            wp_list_categories($cat_args);
            wp_list_pages($page_args);
        } elseif ($show=='pc'){
            wp_list_pages($page_args);
            wp_list_categories($cat_args);
        }

        echo'</ul>';
    }
}

if ( function_exists('wp_nav_menu')&&itx_get_option('menu','wp_menu')){
    register_nav_menu( 'primary' , 'Primary Navigation');
}
?>